package com.zgjkhis.modules.system.rest;

import com.zgjkhis.logging.aop.log.Log;
import com.zgjkhis.modules.security.security.LoginUserUtil;
import com.zgjkhis.modules.system.service.DrugService;
import com.zgjkhis.modules.system.service.DrugWareHousingDetailService;
import com.zgjkhis.modules.system.service.dto.DrugRemainQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author yxl
 * @Description
 * @Date 2021/7/15 17:47
 **/
@Api(tags = "系统：首页")
@RestController
@RequestMapping("/api/home/")
public class HomeController {

    @Resource
    private DrugWareHousingDetailService drugWareHousingDetailService;
    @Resource
    private DrugService drugService;

    @Log("首页数据")
    @ApiOperation("首页数据")
    @GetMapping("/data")
    public ResponseEntity<Object> getData() {
        Map<String, Object> data = new HashMap<>();
        String pharmacyId = LoginUserUtil.getPharmId();

        // 有效期提醒
        DrugRemainQueryCriteria criteria = new DrugRemainQueryCriteria();
        criteria.setPharmacyId(pharmacyId);
        criteria.setFlag(7);

        data.put("remains", this.drugWareHousingDetailService.findRemainList(criteria));

        // 库存预警
        data.put("stockWarning", this.drugService.findStockWarning(pharmacyId));

        return new ResponseEntity<>(data, HttpStatus.OK);
    }

}
